import org.apache.bcel.classfile.Field;

import com.rshacking.rhf.files.ClassContainer;
import com.rshacking.rhf.updater.Transform;
import com.rshacking.rhf.updater.hooks.ClassHook;
import com.rshacking.rhf.updater.hooks.HooksList;

/**
 * @author Mark
 *
 */
public class InterfaceTransform extends Transform {

    public boolean canActivate(HooksList hooks, ClassContainer cc) {
        int count = 0;
        for (Field field : cc.getBCEL().getFields())
                if (field.getType().getSignature().equals("[Ljava/lang/Object;"))
                        if (++count > 20)
                                return true;
        return false;
}

	@Override
	public boolean execute(HooksList hooks, ClassContainer cc) {
		ClassHook ch = hooks.add("Interface", cc.getName());
		for (Field field : cc.getBCEL().getFields()) {
			if (!field.isStatic()) {
				String signature = field.getType().getSignature();
				if (signature.equals("[Ljava/lang/String;"))
					ch.add("Actions", field);
				else if (signature.equals("[L" + cc.getBCEL().getClassName()
						+ ";"))
					ch.add("Children", field);
			}
		}
		return true;
	}

}